﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace DexLicenseKey
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        private String modulosKey = "G";
        private int versao = 0;

        public MainWindow()
        {
            InitializeComponent();
            txtDataAdesao.Text = DateTime.Now.ToShortDateString();
            txtDataExpiracao.Text = getFinalDate(txtDataAdesao.Text.ToString());
        }

        private string getFinalDate(string dataAdesao)
        {
            DateTime dataFinal;

            DateTime dataInicial = Convert.ToDateTime(dataAdesao);

            int dia = dataInicial.Day;
            int mes = dataInicial.Month + 1;
            int ano = dataInicial.Year;

            dataFinal = new DateTime(ano,mes,dia);

            return dataFinal.ToShortDateString();
        }

        private void MarcarTodos(object sender, RoutedEventArgs e)
        {
            var check = sender as CheckBox;

            if (check.IsChecked == true)
            {
                mRHumanos.IsChecked = true;
                mFinanceiro.IsChecked = true;
                mFiscal.IsChecked = true;
                mOrcamento.IsChecked = true;
                mOrdemServico.IsChecked = true;
                mEstoque.IsChecked = true;

                modulosKey += "RFFOOE";
            }
            else
            {
                mRHumanos.IsChecked = false;
                mFinanceiro.IsChecked = false;
                mFiscal.IsChecked = false;
                mOrcamento.IsChecked = false;
                mOrdemServico.IsChecked = false;
                mEstoque.IsChecked = false;
            }
        }

        private void InformarQntdeMaquina(object sender, RoutedEventArgs e)
        {
            if (ckWeb.IsChecked == true)
            {
                versao = 1;
                lblQntdeMaquinas.Visibility = Visibility.Visible;
                txtQntdeMaquinas.Visibility = Visibility.Visible;
            }
            else {
                lblQntdeMaquinas.Visibility = Visibility.Hidden;
                txtQntdeMaquinas.Visibility = Visibility.Hidden;
            }
        }



        private void GerarLincensa(object sender, RoutedEventArgs e)
        {
            
        }

        private void GerarHashCode(object sender, KeyEventArgs e)
        {
            Random rnd = new Random();
            string valor = string.Empty;

            txtHashComposto.Text = "";

            // Caso seja 1, sorteia letras  
            
            valor += Convert.ToChar(rnd.Next(65, 91));
         
            // Caso seja 1, sorteia numeros 
            valor += Convert.ToChar(rnd.Next(48, 58));

            // Versão Desktop ou Web
            valor += "VDW"+versao.ToString();

            if (valor.Length == 4) {
                valor += '-';
            }

            txtHashComposto.Text += valor;
        }

    }
}
